home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / netz / envoyempire / source / muiempire.service / muiempire.bak2 < prev    next >
Text File  |  1995-07-10  |  6KB  |  192 lines

  1. /*************************************************************************
  2.  
  3. MUIEmpire Service written by Karl Bellve
  4.  
  5.    
  6. *************************************************************************/
  7.  
  8.  
  9. #include <exec/types.h>
  10. #include <exec/memory.h>
  11. #include <exec/ports.h>
  12.  
  13. #include <utility/tagitem.h>
  14. #include <workbench/startup.h>
  15.  
  16. #include <dos/dostags.h>
  17. #include <dos.h>
  18.  
  19. #include <envoy/nipc.h>
  20. #include <envoy/services.h>
  21.  
  22. #include <pragmas/dos_pragmas.h>
  23. #include <pragmas/exec_pragmas.h>
  24. #include <pragmas/nipc_pragmas.h>
  25. #include <pragmas/utility_pragmas.h>
  26. #include <clib/dos_protos.h>
  27. #include <clib/exec_protos.h>
  28. #include <clib/nipc_protos.h>
  29. #include <clib/alib_protos.h>
  30. #include <clib/utility_protos.h>
  31.  
  32. #include "string.h"
  33. #include "stdio.h"
  34. struct Library *UtilityBase, *DOSBase;
  35.  
  36. #define ASM           __asm
  37. //StartServiceA   (struct TagItem *);
  38. //GetServiceAttrsA(struct TagItem *);
  39.  
  40. struct StartMsg
  41. {
  42.   struct WBStartup wbmsg;    
  43.   struct PhonySegList *psl;
  44.   struct Segment *rsl;
  45.   struct MsgPort *parent;  
  46.   char   name[30];
  47. };
  48.  
  49. struct PhonySegList {
  50.         BPTR    psl_NextSeg;            /*  BPTR to next element in list  */
  51.         UWORD   psl_JMP;                /*  A 68000 JMP abs.l instruction  */
  52.         LONG    (*psl_EntryPoint)();    /*  The address of the function  */
  53. };
  54.  
  55.  
  56. struct PhonySegList psltemplate = {
  57.         NULL,                           /*  No next element.              */
  58.         0x4EF9,                         /*  JMP abs.l                     */
  59.         NULL                            /*  Argument for JMP instruction  */
  60. };
  61.  
  62. int x;
  63.  
  64. VOID __saveds ASM LIBRexxReserved() { return; }
  65.  
  66.  
  67. /**************************************************************************
  68. StartService() - Starts the service.
  69.  
  70.     Services Manager calls this function to attempt to start the service.
  71.  
  72.     INPUTS: TagList passed in by Services Manager
  73.     OUTPUT: Error Code - Non Zero Means Error
  74. **************************************************************************/
  75. ULONG __saveds ASM LIBStartServiceA(register __a0 struct TagItem *st_list)
  76. {
  77.     struct TagItem cptags[3];
  78.     struct Process *lpdproc;
  79.     struct MyStartMsg *startupmsg;
  80.     struct MsgPort *parent,*child;
  81.     struct PhonySegList *fakelist = NULL;
  82.     char   name[20];
  83.     BOOL   status = FALSE;
  84.     UBYTE  sigbit;
  85.     ULONG  MUIEmpireError = 0;
  86.     
  87.     
  88.     x++;
  89.     sprintf(&name[0],"empireserver.%d\0",x);
  90.     parent = CreatePort(NULL, NULL);
  91.     if (parent) {
  92.        if (!(fakelist = (struct PhonySegList *)
  93.            AllocMem (sizeof(struct PhonySegList), NULL)  ))
  94.          {
  95.          DeletePort(parent);
  96.          return(1);
  97.          }
  98.          CopyMem (&psltemplate, fakelist, sizeof(PhonySegList) );
  99.          fakelist->psl_EntryPoint = NULL;
  100.  
  101.         
  102.         
  103.         if (seglist = NewLoadSeg("Empire:EnvoyEmpireServer",NULL)) {
  104.     
  105.             cptags[0].ti_Tag  = NP_Seglist;
  106.             cptags[0].ti_Data = seglist;
  107.             cptags[1].ti_Tag  = NP_Name;
  108.             cptags[1].ti_Data = (ULONG) &name[0];
  109.             cptags[2].ti_Tag  = TAG_DONE;
  110.             cptags[2].ti_Data = NULL;
  111.             
  112.             startupmsg = (struct MyStartMsg *) AllocMem(sizeof(struct MyStartMsg), NULL);
  113.             
  114.             if (startupmsg) {
  115.                if (child = (struct MsgPort *)CreateProc (cname, priority, (BPTR) startupmsg->rsl, stacksize) )
  116.                  port = (struct MsgPort *) lpdproc;
  117.                  startupmsg->wbmsg.sm_Message.mn_Node.ln_Type = NT_MESSAGE;
  118.                  startupmsg->wbmsg.sm_Message.mn_Node.ln_Pri  = 0;
  119.                  startupmsg->wbmsg.sm_Message.mn_ReplyPort    = parent;
  120.                  startupmsg->wbmsg.sm_Process = child;
  121.                  startupmsg->wbmsg.sm_Segment = (BPTR) startupmsg->rsl;
  122.                  startupmsg->wbmsg.sm_NumArgs = 0L;
  123.                  startupmsg->wbmsg.sm_ToolWindow = NULL;
  124.                  startupmsg->wbmsg.sm_ArgList = NULL;
  125.                  startupmsg->psl = fakelist;     /** for cleanup **/
  126.                  startupmsg->rsl = (struct Segment *)seglist;
  127.                  startupmsg->parent = parent;
  128.                  strcpy(startupmsg->name, name);
  129.                  
  130.                  PutMsg(child, (struct Message *) startupmsg);
  131.                  Wait(1L<<parent->mp_SigBit);
  132.                  
  133.               }
  134.               FreeMem(startupmsg, (long) sizeof(struct MyStartMsg));
  135.             }
  136.             
  137.             if(tag=FindTagItem(SSVC_EntityName,st_list))
  138.               {
  139.               strcpy((char *)tag->ti_Data,name);
  140.               } 
  141.             else MUIEmpireError = 2;
  142.             FreeMem (fakelist, (LONG) sizeof (struct PhonySegList));
  143.         }
  144.         else MUIEmpireError = 3;
  145.         DeletePort(parent);
  146.     }    
  147.        
  148.     return(MUIEmpireError);
  149. }
  150.  
  151.  
  152.  
  153. /*************************************************************************
  154. GetServiceAttrsA() - Get service attributes
  155.  
  156.     Required to return the name of the service in tag SVCAttrs_Name
  157.  
  158.     INPUTS: TagList from services manager to process/update
  159. *************************************************************************/
  160. VOID __saveds ASM LIBGetServiceAttrsA(register __a0 struct TagItem *tagList)
  161. {
  162.     struct TagItem *ti;
  163.  
  164.     if(ti=FindTagItem( SVCAttrs_Name, tagList))
  165.     {
  166.         strcpy((STRPTR)ti->ti_Data,"MUIEmpire_Service");
  167.     }
  168. }
  169.  
  170.  
  171. int __saveds __UserLibInit(void) {
  172.   
  173.   UtilityBase = OpenLibrary("utility.library",37);
  174.   DOSBase = OpenLibrary("dos.library",37);
  175.   
  176.   if (!DOSBase) return(1);
  177.   if (!UtilityBase){
  178.       CloseLibrary(DOSBase);
  179.       return (1);
  180.   }
  181.   
  182.   return(0);
  183. }
  184.  
  185. int __saveds __UserLibCleanup(void) {
  186.   
  187.   CloseLibrary(DOSBase);
  188.   CloseLibrary(UtilityBase);
  189.    
  190.   return(0);
  191. }
  192.